/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package luft27.mavlinkadapter;

import luft27.comm.*;
import luft27.propertytree.PropertyNode;

/**
 *
 * @author amalikov
 */
public class SerialStreamFactory {
	public static SerialStream createFromPropertyTree(PropertyNode link) {
		switch (link.get().asString()) {
		case "com":
			return new COMStream(
					link.get("/com/port").asString(), 
					link.get("/com/baudrate").asInt(), 
					link.get("/timeout").asInt());
		case "udp":
			return new UDPStream(
					link.get("/udp/self").asString(),
					link.get("/udp/selfport").asInt(),
					link.get("/udp/remote").asString(),
					link.get("/udp/remoteport").asInt(),
					link.get("/timeout").asInt());
		case "tcp":
			return new TCPStream(
					link.get("/tcp/host").asString(),
					link.get("/tcp/port").asInt(),
					link.get("/tcp/handshake").asString(),
					link.get("/tcp/server").asBool(),
					link.get("/timeout").asInt());
			
		default:
			return new NullStream();
		}
	}
}
